#version 460 core

layout(location = 0) in vec3 worldPos;
layout(location = 1) in vec3 normalWorldSpace;

layout(location = 0) out vec4 outColor;

uniform vec3 viewPos;

const vec3 LIGHT_DIR = normalize(vec3(1.0, -3.0, -1.0));
const float AMBIENT_STRANGTH = 0.1;
const float SPECULAR_STRENGHT = 0.5;
const vec3 LIGHT_COLOR = vec3(0.5, 0.6, 0.7);
const vec3 OBJ_COLOR = vec3(0.3, 0.3, 0.3);

void main() {
    // 计算间接光照
    vec3 ambient = AMBIENT_STRANGTH * LIGHT_COLOR;

    // 计算漫反射
    float diff = max(dot(normalWorldSpace, LIGHT_DIR), 0.0);
    vec3  diffuse = diff * LIGHT_COLOR;

    // 计算高光
    vec3 viewDir = normalize(viewPos - worldPos);
    vec3 reflectDir = reflect(-LIGHT_DIR, normalWorldSpace);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), 64);
    vec3  specular = SPECULAR_STRENGHT * spec * LIGHT_COLOR;

    vec3 result = (ambient + diffuse + specular) * OBJ_COLOR;

    outColor = vec4(result, 1.0);
}
